package com.qtummatrix.utils;

import com.qtummatrix.entity.ClientEntity;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * create by Gongshiyong  2019-12-07 11:03
 */
public class ReadExcel {
    private static List<String[]> readExcel(String filePath) throws IOException, BiffException {

        List<String[]> list = new ArrayList<String[]>();
        // 创建输入流
        InputStream stream = new FileInputStream(filePath);
        // 获取Excel文件对象
        Workbook rwb = Workbook.getWorkbook(stream);
        // 获取文件的指定工作表 默认的第一个
        Sheet sheet = rwb.getSheet(0);
        // 行数(表头的目录不需要，从1开始)
        for (int i = 0; i < sheet.getRows(); i++) {
            // 创建一个数组 用来存储每一列的值
            String[] str = new String[sheet.getColumns()];
            Cell cell = null;
            // 列数
            for (int j = 0; j < sheet.getColumns(); j++) {
                // 获取第i行，第j列的值
                cell = sheet.getCell(j, i);
                str[j] = cell.getContents();
            }
            // 把刚获取的列存入list
            list.add(str);
        }
        return list;
    }


    public List<ClientEntity> hu() throws BiffException, IOException {

        List<String[]> list = new ArrayList<String[]>();
        list = readExcel("D:\\message\\abcd.xls");
        List<ClientEntity> list1 = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            ClientEntity clientEntity = new ClientEntity();
            String[] str = (String[]) list.get(i);
            for (int j = 0; j < str.length; j++) {
                clientEntity.setID(str[0]);
                clientEntity.setCystimName(str[1]);
                clientEntity.setBank(str[2]);
                clientEntity.setRate(str[3]);
                clientEntity.setLimit(str[4]);
                clientEntity.setDeadline(str[5]);
                clientEntity.setInterestType(str[6]);
                clientEntity.setReport(str[7]);
                clientEntity.setMid(str[8]);
                clientEntity.setWId1(str[9]);
                clientEntity.setIssue1(str[10]);
                clientEntity.setWId2(str[11]);
                clientEntity.setIssue2(str[12]);
                clientEntity.setWId3(str[13]);
                clientEntity.setIssue3(str[14]);
                clientEntity.setWId4(str[15]);
                clientEntity.setIssue4(str[16]);
                clientEntity.setWId5(str[17]);
                clientEntity.setIssue5(str[18]);
                clientEntity.setWId6(str[19]);
                clientEntity.setIssue6(str[20]);
                clientEntity.setWId7(str[21]);
                clientEntity.setIssue7(str[22]);
                clientEntity.setWId8(str[23]);
                clientEntity.setIssue8(str[24]);
                clientEntity.setWId9(str[25]);
                clientEntity.setIssue9(str[26]);
                clientEntity.setWId10(str[27]);
                clientEntity.setIssue10(str[28]);
            }
            list1.add(clientEntity);
        }
        return list1;
    }
}
